function CustomerSelect_Code() {
	var buffer = new StringBuffer();
	buffer.append('<div id="find2" class="finds2" style="z-index:100;"><div class="searchinput ui-border-radius"><input id="keyword2" class="bordersolid" type="text" value="" onblur="Show_Search2()" onkeyup="CustomerSelect_Search();"/><div id="searchicon2" class="searchicon"><img src="img/jing.jpg"/></div><div id="searchicons2" class="searchicons"><img src="img/jings.jpg"/></div></div></div>');
	buffer.append('<div class="horizen border-bottom" style="z-index:100;"></div>');
	return buffer.toString();
};

function CustomerSelect_Data(data) {
	var buffer = new StringBuffer();
	$(data).each(function(i,info){
		buffer.append('<div class="customerlist border-bottom" id="'+info.ID+'" address="'+info.Address+'"><div class="customername">'+info.Name+'</div><div class="customerinfo"><div class="state">'+info.State+'</div><div class="lastconntime">'+info.LastConnDate.ToTime()+'</div></div></div>');
	});
	return buffer.toString();
};

function Receive_CustomerSelect(pageindex)
{
	var data = {};
			data.act = "Find_Customer";
			data.userid=userid;
			data.comid=comid;
			data.pageindex=pageindex;
			data.source=source;
			data.pagesize=PAGE_SIZE20;
			data.keyword = $("#keyword2").val();
		    data.timer = "";
		    data.state = "";
		    data.type = 1;
		    data.lowers = "";
		    data.sign=GetSign(data.act);
			
			mui.getJSON(crm_domain, data, function(json) {
				if(json.data.list.length>0)
				{
					if(pageindex==1)
					{
						$("#contentlist4").html(CustomerSelect_Data(json.data.list));
					}else{
						$("#contentlist4").append(CustomerSelect_Data(json.data.list));
					}
					setTimeout(function(){
						Init_CustomerSelect();
						myScroll3.refresh();
					},500); //需要延迟500毫秒加载，否则当数量少时不能下拉
					if(json.data.list.length!=data.pagesize)
					{
						$("#loading4").html("");
					}else{
						$("#loading4").html('<img src="img/loading.gif"/>');
					}
				}else
				{
					if(pageindex==1)
					{
						$("#contentlist4").html("");
						$("#loading4").html("主人，没有找到您需要的数据");
					}
					else
					{
						$("#loading4").html("没有更多了");
					}
				}
				
         		pageindex = parseInt($("#divmsg4").attr("pageindex"))+1;
         		$("#divmsg4").attr("pageindex",pageindex);
         		
         		
			});
};

function CustomerSelect_Search(){
	pageindex=1;
	$("#divmsg4").attr("pageindex","0");
	Receive_CustomerSelect(1);
};

function Init_CustomerSelect()
{
	mui("#contentlist4").off("tap",".customerlist");
	mui("#contentlist4").on("tap",".customerlist",function(){
		$("#txt_customerid").val($(this).find(".customername").html()).attr("customerid",$(this).attr("id"));
		$("#txt_address").val($(this).attr("address"));
		var data = {};
		data.userid=userid;
		data.comid=comid;
		data.source=source;
        data.act = "Find_Contact_ByCustomerID";
        data.customerid = $(this).attr("id");
        data.sign=GetSign(data.act);        
		mui.getJSON(crm_domain, data, function (json) {
            if (json.state) {
                var str = "";
                $.each(json.data.list, function (i, info) {
                    var mobile = info.Mobile;
                    if (info.Mobile == "") { mobile = info.Phone; }
                    if(i==0 && $("#txt_mobile").length>0){$("#txt_mobile").val(mobile);}
                    str += "<option value='" + info.ID + "' mobile='" + mobile + "'>" + info.Name + "</option>";
                });
                $("#txt_contactid").html(str);
            } else {
            }
        });
		CloseWindow();
	});
};


